<template>
<h2>添加科室</h2>
<table border="1">
    <tr>
        <td>科室名称</td>
        <td>
            <input type="text" v-model="info.KeiShiName">
        </td>
    </tr>
    <tr>
        <td>科室介绍</td>
        <td>
           <textarea v-model="info.KeiShiInfo"></textarea>
        </td>
    </tr>
   
    <tr>
        <td>科室人数</td>
        <td>
            <input type="number" v-model="info.KeiShiNum">
        </td>
    </tr>
    
    <tr>
        <td></td>
        <td>
            <input type="button" value="录入" @click="SaveData">
        </td>
    </tr>
</table>


</template>
<script setup lang="ts">
import axios from "axios";
import { onMounted ,ref} from "vue";

import{useCounterStore}from '../././././../stores/counter.ts'


const Counters=useCounterStore();

onMounted(()=>{
    GetUtype();
})

const info=ref({
    KeiShiName:"",
    KeiShiInfo:"",
   
    KeiShiNum:"",
   
})

const UserType=ref("");
const SaveData=()=>{

    if(UserType.value=="用户"){
        alert("当前用户没有权限进行该操作");
        return;
    }

axios.post('https://localhost:7133/api/KeiShi/AddKeiShiInfo',{

    KeiShiName:info.value.KeiShiName,
    KeiShiInfo:info.value.KeiShiInfo,
   
    KeiShiNum:info.value.KeiShiNum,
    D_AddUser:Counters.MemberName
})
.then(res=>{
    
    if(res.data==-1){
        alert("科室已经存在");
    }
    else if(res.data>0){
        alert("录入成功");
    }
    else{
        alert("录入失败");
    }
})

}


const GetUtype=()=>{
    axios.get('https://localhost:7133/api/KeiShi/GetMemberType',
    {
        params:{
            MemberName:Counters.MemberName
        }
    }
    )
    .then(res=>{
        UserType.value=res.data[0];
    })
}
</script>